package com.cms.controller;
 

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cms.service.ReportService;
import com.google.gson.Gson;

@Controller
public class UserStatisticsController extends BaseController{

	  @Autowired
	  private ReportService reportService;
	  
	  @RequestMapping(value="/userStatistics.do")
	  public String userStatistics(HttpServletRequest req,HttpServletResponse response,ModelMap map)throws Exception
	  { 
		   map.put("userStatisticsList", this.reportService.getReportResult("userStatistics", Collections.EMPTY_MAP));
		   return "userStatistics/userStatisticsMain.html";
	  }
	  
	  
	  @RequestMapping(value="/userStatistics/userStatisticsData.do")
	  public void userTypeChart(HttpServletRequest req,HttpServletResponse response,ModelMap map)throws Exception
	  { 
		  Map<String,Object>data= this.reportService.querySingleResult("userStatistics", Collections.EMPTY_MAP);
		  Map<String,Object>result =new HashMap<String, Object>();
		  Map<String,Object>userType = new HashMap<String, Object>();
		  Map<String,Object>userStatus = new HashMap<String, Object>();
		  Map<String,Object>userVirtual = new HashMap<String, Object>();
		  
		  Map<String,Object>temp = null;
		  List<Map<String, Object>>userTypeList = new ArrayList<Map<String,Object>>();
		  temp = new HashMap<String, Object>();
		  temp.put("name", "会员("+data.get("userCount")+")");
		  temp.put("y", data.get("userCount"));
		  userTypeList.add(temp);
		  
		  temp = new HashMap<String, Object>();
		  temp.put("name", "代理("+data.get("proxyCount")+")");
		  temp.put("y", data.get("proxyCount"));
		  userTypeList.add(temp);
		  
		  List<Map<String, Object>>userStatusList = new ArrayList<Map<String,Object>>();
		  temp = new HashMap<String, Object>();
		  temp.put("name", "在线("+data.get("onlineCount")+")");
		  temp.put("y", data.get("onlineCount"));
		  userStatusList.add(temp);
		  
		  temp = new HashMap<String, Object>();
		  temp.put("name", "离线("+data.get("offlineCount")+")");
		  temp.put("y", data.get("offlineCount"));
		  userStatusList.add(temp);
		  
		  
		  List<Map<String, Object>>userVirtualList = new ArrayList<Map<String,Object>>();
		  temp = new HashMap<String, Object>();
		  temp.put("name", "虚拟("+ data.get("virtualAccount")+")");
		  temp.put("y", data.get("virtualAccount"));
		  userVirtualList.add(temp);
		  
		  temp = new HashMap<String, Object>();
		  temp.put("name", "实体("+data.get("nonVirtualAccount")+")");
		  temp.put("y", data.get("nonVirtualAccount"));
		  userVirtualList.add(temp);
		  
		  userType.put("title", "用户类型统计");
		  userStatus.put("title", "用户状态统计");
		  userVirtual.put("title", "账号类型统计");
		  userType.put("data", userTypeList);
		  userStatus.put("data", userStatusList);
		  userVirtual.put("data", userVirtualList);
		  
		  result.put("userType", userType);
		  result.put("userStatus",userStatus); 
		  result.put("userVirtual",userVirtual); 
		  this.renderText(response, new Gson().toJson(result));
	  }
	  
}
